home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 136_01.zip / DUMPSTAR.C < prev    next >
Text File  |  1993-06-01  |  12KB  |  644 lines

  1. /*    HEADER:  CUG136.08;
  2.     TITLE:        DUMPSTAR;
  3.     VERSION:    1.00;
  4.     DATE:        9/10/1984;
  5.     DESCRIPTION:    "DumpStar Video Game";
  6.     KEYWORDS:    game,video;
  7.     SYSTEM:        CP/M;
  8.     FILENAME:    DUMPSTAR.C;
  9.     AUTHORS:    R. Rodman;
  10.     COMPILERS:    C/80;
  11. */
  12.  
  13. /*    DUMPSTAR
  14.  
  15.     830721 remove WS references
  16.     830730 both x and y for enemies
  17.     830908 convert to c
  18.     830912 try to get working
  19.     830913 correct bug in movea, make 40 cols
  20.     830913 make 64 cols per sector
  21.     830916 add blast routine
  22.     830917 various fixes
  23.     830926 acceleration, other misc changes
  24.     830929 ground by calculation
  25.     831013 some refinements
  26.     831014 more refinements
  27.     840306 changes for adm5
  28.     840811 22 aliens, strategy aliens, became DUMPSTAR
  29.     840910 read terminal file
  30. */
  31.  
  32. #include "printf.c"
  33. #include "random.c"
  34.  
  35. /* value of ships includes the one you're playing with */
  36.  
  37.     int ax[ 22 ], ay[ 22 ], dx[ 22 ], dy[ 22 ];
  38.     char as[ 22 ][ 3 ];
  39.     int aliens, ships, other, gnd1ind, gnd2ind;
  40.     int ux, uy, uface, uspeed, uaccel, score, oldsco;
  41.  
  42.     char hi_name[ 10 ][ 16 ];
  43.     int hi_cnt, hi_scor[ 10 ];
  44.  
  45.     char trmbuf[ 128 ];
  46.     char *p;
  47.     int i;
  48.  
  49.     int width, height, defint, uselst, yfirst, method, addx, addy;
  50.     char *inistr, *clrscn, *clreos, *clreol, *curoff, *curon,
  51.         *curbeg, *curmid, *curend, *hiint, *loint, *revvid, *norvid,
  52.         *inslin, *dellin;
  53.  
  54. /* main program */
  55.  
  56. main()
  57. {
  58.     char wplayer(), inkey();
  59.  
  60.     terminit();            /* init terminal file */
  61.  
  62.     while( wplayer() != 'Q' ) {    /* wait for a player */
  63.  
  64.         init();
  65.         take();            /* take a ship */
  66.  
  67.         while( ships && aliens ) {
  68.             ckkey();    /* check user input */
  69.  
  70.             update();    /* update screen */
  71.  
  72.             movea();    /* move aliens */
  73.  
  74.             if( ux == 999 ) take();
  75.         }
  76.  
  77.         if( ships ) {
  78.             goxy( 0, 20 );
  79.             puts( "YOU GOT THEM ALL! PRESS A KEY: " );
  80.             puts( curon );
  81.             while( ! inkey() );
  82.         }
  83.     }
  84.  
  85.     puts( clrscn );        /* exit if player typed 'Q' */
  86.     puts( curon );
  87.  
  88.     if( defint != 'H' ) puts( loint );
  89. }
  90.  
  91. terminit()
  92. {
  93.     int t, u;
  94.     char *p;
  95.     t = fopen( "TERMINAL.SYS", "r" );
  96.  
  97.     if( t == 0 ) {
  98.         puts( "Run TERMINAL first, please." );
  99.         exit();
  100.     }
  101.  
  102.     p = &trmbuf[ 0 ];
  103.  
  104.     read( t, p, 128 );
  105.  
  106.     fclose( t );
  107.  
  108.     width = *p++;
  109.     height = *p++;
  110.     defint = *p++;
  111.     uselst = *p++;
  112.     yfirst = *p++;
  113.     method = *p++;
  114.     addx = *p++;
  115.     addy = *p++;
  116.  
  117.     for( u = 1; u <= 15; u++ ) {
  118.         switch( u ) {
  119.             case 1 : inistr = p; break;
  120.             case 2 : clrscn = p; break;
  121.             case 3 : clreos = p; break;
  122.             case 4 : clreol = p; break;
  123.             case 5 : curoff = p; break;
  124.             case 6 : curon = p; break;
  125.             case 7 : curbeg = p; break;
  126.             case 8 : curmid = p; break;
  127.             case 9 : curend = p; break;
  128.             case 10 : hiint = p; break;
  129.             case 11 : loint = p; break;
  130.             case 12 : revvid = p; break;
  131.             case 13 : norvid = p; break;
  132.             case 14 : inslin = p; break;
  133.             case 15 : dellin = p; break;
  134.         }
  135.  
  136.         p++; p++; p++; p++;
  137.         p++; p++; p++; p++;
  138.     }
  139. }
  140.  
  141. /* output a coordinate */
  142.  
  143. coord( c )
  144. int c;
  145. {
  146.     switch( method ) {
  147.         case '0' : putchar( c ); break;
  148.         case '1' : {
  149.             if( c >= 100 ) {
  150.                 putchar( '0' + c / 100 );
  151.                 c %= 100;
  152.             }
  153.             if( c >= 10 ) {
  154.                 putchar( '0' + c / 10 );
  155.                 c %= 10;
  156.             }
  157.             putchar( '0' + c );
  158.         }
  159.     }
  160. }
  161.  
  162. /* position cursor */
  163.  
  164. goxy( x, y )
  165. int x, y;
  166. {
  167.     puts( curbeg );
  168.     if( yfirst == 'Y' ) coord( y + addy );
  169.         else coord( x + addx );
  170.     puts( curmid );
  171.     if( yfirst == 'Y' ) coord( x + addx );
  172.         else coord( y + addy );
  173.     puts( curend );
  174. }
  175.  
  176. /* get a random number between 0 and range */
  177.  
  178. rnd( range )
  179. int range;
  180. {
  181.     unsigned q, rand();
  182.  
  183.     q = rand();
  184.     return( q % range );
  185. }
  186.  
  187. /* initialize game */
  188.  
  189. init()
  190. {
  191.     int j;
  192.  
  193.     srand( 0 );
  194.  
  195.     score = 0;
  196.     oldsco = 0;
  197.     aliens = 22;
  198.  
  199.     for( j = 0; j < 22; j++ ) {
  200.         ax[ j ] = rnd( 512 );
  201.         dx[ j ] = 2 * rnd( 2 ) - 1;
  202.         dy[ j ] = 2 * rnd( 2 ) - 1;
  203.         ay[ j ] = rnd( 22 );
  204.     }
  205.  
  206.     for( j = 0; j < 8; ++j ) {
  207.         dx[ j ] = 0;        /* mines */
  208.         dy[ j ] = 0;
  209.         strcpy( as[ j ], "::" );
  210.     }
  211.  
  212.     for( j = 8; j < 16; ++j )
  213.         if( dx[ j ] > 0 ) strcpy( as[ j ], ">o" );
  214.             else strcpy( as[ j ], "o<" );    /* fighters */
  215.  
  216.     for( j = 16; j < 22; ++j )
  217.         if( dx[ j ] > 0 ) strcpy( as[ j ], ")O" );
  218.             else strcpy( as[ j ], "O(" );    /* flagships */
  219.  
  220.     ships = 4;    /* initial count of ships, extra for init take() */
  221.  
  222.     gnd1ind = 0;
  223.     gnd2ind = 0;
  224.     other = 0;
  225. }
  226.  
  227. /* check keyboard for a char */
  228.  
  229. char inkey()
  230. {
  231.     return toupper( bdos( 6, 0xFF ) & 0x7F );
  232. }
  233.  
  234. /* send out string */
  235.  
  236. puts( c )
  237. char *c;
  238. {
  239.     while( *c ) putchar( *c++ );
  240. }
  241.  
  242. /* wait for someone to play */
  243.  
  244. char wplayer()
  245. {
  246.     char c;
  247.  
  248.     puts( clrscn );
  249.  
  250.     puts( "\n\n\n" );
  251.  
  252.     puts( "[[[[[[                                 \n" );
  253.     puts( "[[[ [[[                                \n" );
  254.     puts( "[[[  [[[ [[[  [[[ [[[[   [[[[ [[[[[[[  \n" );
  255.     puts( "[[[  [[[ [[[  [[[ [[[[[ [[[[[ [[[  [[[ \n" );
  256.     puts( "[[[  [[[ [[[  [[[ [[[[[[[[[[[ [[[ [[[  \n" );
  257.     puts( "[[[  [[[ [[[  [[[ [[[ [[[ [[[ [[[[[[   \n" );
  258.     puts( "[[[  [[[ [[[  [[[ [[[     [[[ [[[      \n" );
  259.     puts( "[[[[[[[   [[[[[[  [[[     [[[ [[[      \n" );
  260.     puts( "                                       \n" );
  261.     puts( "  [[[[[[[[[[[[[[[[[  [[[      [[[[[[[  \n" );
  262.     puts( " [[[[       [[[     [[[[[     [[[  [[[ \n" );
  263.     puts( "  [[[[      [[[    [[[ [[[    [[[ [[[  \n" );
  264.     puts( "   [[[[     [[[   [[[   [[[   [[[[[[   \n" );
  265.     puts( "    [[[[    [[[  [[[[[[[[[[[  [[[[[[[  \n" );
  266.     puts( "     [[[[   [[[ [[[       [[[ [[[  [[[ \n" );
  267.     puts( "      [[[[                             \n" );
  268.     puts( "]]]]]][[[                              \n" );
  269.  
  270.     puts( "\n\n" );
  271.  
  272.     puts( curon );
  273.     puts( "PRESS ANY KEY TO PLAY (Q TO QUIT): " );
  274.  
  275.     while( c = inkey() );    /* clear up any keypresses pending */
  276.     while( ! ( c = inkey() ));    /* wait for a new keypress */
  277.  
  278.     puts( curoff );
  279.  
  280.     return( c );
  281. }
  282.  
  283. /* set up screen */
  284.  
  285. setup()
  286. {
  287.     int j;
  288.  
  289.     puts( clrscn );
  290.     puts( curoff );
  291.  
  292.     for( j = 0; j <= 23; j++ ) {
  293.         goxy( 64, j );
  294.         puts( loint );
  295.         putchar( '|' );
  296.         puts( hiint );
  297.     }
  298.  
  299.     /* show ships in storage, ships - 1 */
  300.  
  301.     for( j = 13; j < ships + 12; j++ ) ship( 67, j, 1 );
  302.  
  303.     ux = 30;
  304.     uy = 14;
  305.     uface = 1;
  306.     uspeed = 1;
  307.     uaccel = 0;
  308.  
  309.     ship( ux, uy, uface );
  310. }
  311.  
  312. /* take a ship away */
  313.  
  314. take()
  315. {
  316.     int k;
  317.  
  318.     --ships;
  319.     if( ! ships ) return;
  320.  
  321.     for( k = 1; k < 30000; k++ );    /* delay */
  322.  
  323.     setup();        /* repaint screen */
  324. }
  325.  
  326. /* add another ship */
  327.  
  328. give()
  329. {
  330.     ships++;
  331.     ship( 65, ships + 13, 1 );
  332. }
  333.  
  334. /* draw ship */
  335.  
  336. ship( x, y, p )
  337. int x, y, p;
  338. {
  339.     goxy( x, y );
  340.     switch( p ) {
  341.         case -1 : puts( "<>==<" ); break;
  342.         case 0 : puts( "     " ); break;
  343.         case 1 : puts( ">==<>" ); break;
  344.     }
  345. }
  346.  
  347. /* evaluate keyboard command */
  348.  
  349. ckkey()
  350. {
  351.     int k;
  352.  
  353.     k = inkey();
  354.  
  355.     switch( k ) {
  356.         case 'Q' : ships = 0; break;
  357.  
  358.         case 'C' : if( uy < 21 ) {
  359.                 ship( ux, uy, 0 );
  360.                 ship( ux, ++uy, uface );
  361.             }; break;
  362.  
  363.         case 'E' : if( uy > 0 ) {
  364.                 ship( ux, uy, 0 );
  365.                 ship( ux, --uy, uface );
  366.             }; break;
  367.  
  368.         case 'S' :    uface = -1;
  369.                 uspeed = 1;
  370.                 uaccel = 0;
  371.                 ship( ux, uy, uface );
  372.                 break;
  373.  
  374.         case 'F' :    uface = 1;
  375.                 uspeed = 1;
  376.                 uaccel = 0;
  377.                 ship( ux, uy, uface );
  378.                 break;
  379.  
  380.         case ' ' :    fire();
  381.                 break;
  382.     }
  383.     uaccel++;
  384.     if( uaccel >= 10 && uspeed < 3 ) {
  385.         ++uspeed;    /* accelerate up to 3 */
  386.         uaccel = 0;
  387.     }
  388. }
  389.  
  390. /* fire a shot */
  391.  
  392. fire()
  393. {
  394.     int ll, ul, j, k;
  395.  
  396.     ll = ux + 5;    /* lower limit */
  397.     ul = 63;
  398.  
  399.     if( uface < 0 ) {
  400.         ll = ux - 2;
  401.         ul = -1;
  402.     }
  403.  
  404.     for( j = ll; j != ul; j += uface ) blast( j, uy, '-' );
  405. }
  406.  
  407. /* move aliens */
  408.  
  409. movea()
  410. {
  411.     int j, k, xx;
  412.     int q_cnt[ 8 ];
  413.  
  414.     for( j = 0; j < 8; j++ ) q_cnt[ j ] = 0;
  415.  
  416.     for( j = 0; j < 22; j++ ) {
  417.         if( ax[ j ] == 999 ) {
  418.             /* alien destroyed */
  419.         } else {
  420.             /* clear old pic of alien */
  421.  
  422.             for( k = 0; as[ j ][ k ]; k++ ) {
  423.                 xx = ax[ j ] + k;
  424.                 if( xx > 511 ) xx -= 512;
  425.  
  426.                 if( ( xx >= 0 ) && ( xx <= 63 ) ) {
  427.                     goxy( xx, ay[ j ] );
  428.                     putchar( ' ' );
  429.                 }
  430.             }
  431.  
  432.             ax[ j ] += dx[ j ];    /* movement of alien */
  433.             ax[ j ] -= uface * uspeed;    /* movement of ship */
  434.             if( ax[ j ] < 0 ) ax[ j ] += 512;
  435.             if( ax[ j ] > 511 ) ax[ j ] -= 512;
  436.  
  437.             ay[ j ] += dy[ j ];
  438.  
  439.             if( ay[ j ] < 0 || ay[ j ] > 21 ) {
  440.                 dy[ j ] = -dy[ j ];    /* reverse */
  441.                 ay[ j ] += dy[ j ];    /* direction */
  442.             }
  443.  
  444. /* now check strategy.  first mines */
  445.  
  446.             if( j < 8
  447.                 && absdif( ax[ j ], ux ) < 6
  448.                 && absdif( ay[ j ], uy ) < 6 ) {
  449.                 xx = ax[ j ];
  450.                 ax[ j ] = 999;    /* get rid of alien */
  451.                 --aliens;
  452.                 explode( xx, ay[ j ] );
  453.             }
  454.  
  455.             if( j >= 8 && j < 16
  456.                 && absdif( ax[ j ], ux ) > 8 ) {
  457.                     dx[ j ] = sign( ux - ax[ j ] );
  458.                     if( dx[ j ] > 0 )
  459.                         strcpy( as[ j ], ">o" );
  460.                         else strcpy( as[ j ], "o<" );
  461.             }
  462.  
  463.             if( j >= 16
  464.                 && absdif( ax[ j ], ux ) > 16 ) {
  465.                     dx[ j ] = sign( ux - ax[ j ] );
  466.                     if( dx[ j ] > 0 )
  467.                         strcpy( as[ j ], ")O" );
  468.                         else strcpy( as[ j ], "O(" );
  469.             }
  470.  
  471. /* draw new pic of alien */
  472.  
  473.             for( k = 0; as[ j ][ k ]; k++ ) {
  474.                 xx = ax[ j ] + k;
  475.                 if( xx > 511 ) xx -= 512;
  476.  
  477.                 if( ( xx >= 0 ) && ( xx <= 63 ) ) {
  478.                     goxy( xx, ay[ j ] );
  479.                     putchar( as[ j ][ k ] );
  480.                 }
  481.  
  482. /* check for collision */
  483.  
  484.                 if( ( xx >= ux && xx <= ux + 4 )
  485.                     && ( ay[ j ] == uy ) ) {
  486.                     ax[ j ] = 999;
  487.                     --aliens;
  488.                     explode( xx, ay[ j ] );
  489.                 }
  490.             }
  491.  
  492.             q_cnt[ ax[ j ] / 64 ]++;
  493.         }
  494.     }
  495.  
  496.     for( j = 0; j < 8; j++ ) {
  497.         switch( j ) {
  498.             case 0 : goxy( 69, 6 ); break;
  499.             case 1 : goxy( 72, 6 ); break;
  500.             case 2 : goxy( 72, 8 ); break;
  501.             case 3 : goxy( 72, 10 ); break;
  502.             case 4 : goxy( 69, 10 ); break;
  503.             case 5 : goxy( 66, 10 ); break;
  504.             case 6 : goxy( 66, 8 ); break;
  505.             case 7 : goxy( 66, 6 ); break;
  506.         }
  507.         printf( "%2d", q_cnt[ j ] );
  508.     }
  509. }
  510.  
  511. /* update score, etc. */
  512.  
  513. update()
  514. {
  515.     char t;
  516.     int i;
  517.  
  518.     if( score != oldsco ) {
  519.         oldsco = score;
  520.         goxy( 66, 0 );
  521.         puts( loint );
  522.         printf( "Score: %d", score );
  523.         puts( hiint );
  524.     }
  525.  
  526.     other = ! other;    /* only repaint gnd1 every other time */
  527.  
  528. /*    ground should look like this, roughly:
  529.  
  530.     _/_______/_______/______|_____\_______\________\_
  531.     /    /    /    |    \    \    \    */
  532.  
  533.     goxy( 0, 23 );
  534.     puts( loint );
  535.     for( i = gnd2ind; i < ( gnd2ind + 63 ); i++ ) {
  536.         if( i % 16 ) putchar( ' ' );
  537.             else if( i - gnd2ind < 30 )
  538.                 putchar( '/' );
  539.                 else if( i - gnd2ind > 34 )
  540.                     putchar( '\\' );
  541.                     else putchar( '|' );
  542.     }
  543.     puts( hiint );
  544.  
  545.     if( ! other ) {
  546.         goxy( 0, 22 );
  547.         puts( loint );
  548.         for( i = gnd1ind; i < ( gnd1ind + 63 ); i++ ) {
  549.             if( i % 12 ) putchar( '_' );
  550.                 else if( i - gnd1ind < 30 )
  551.                     putchar( '/' );
  552.                     else if( i - gnd1ind > 34 )
  553.                         putchar( '\\' );
  554.                         else putchar( '|' );
  555.         }
  556.         puts( hiint );
  557.  
  558.         gnd1ind += uface * uspeed;
  559.     }
  560.  
  561.     puts( hiint );
  562.  
  563.     gnd2ind += uface * uspeed;
  564. }
  565.  
  566. /* blast a location */
  567.  
  568. blast( x, y, p )
  569. int x, y;
  570. char p;
  571. {
  572.     int k, tx;
  573.  
  574.     if(( x > 63 ) || ( x < 0 )) return;
  575.  
  576.     goxy( x, y );
  577.     putchar( p );
  578.  
  579.     if(( x >= ux && x <= ux + 4 ) && y == uy ) {
  580.         tx = ux;
  581.         ux = 999;
  582.         explode( tx, uy );        /* explode you */
  583.     }
  584.  
  585.     for( k = 0; k < 22; k++ ) {
  586.         if( ( ay[ k ] == y ) && ( ax[ k ] == x ) ) {
  587.             tx = ax[ k ];        /* save x */
  588.             ax[ k ] = 999;        /* remove alien */
  589.             --aliens;        /* count down aliens left */
  590.             score += 10;        /* add 10 points */
  591.             explode( tx, ay[ k ] );
  592.         }
  593.     }
  594.  
  595.     for( k = 1; k < 150; k++ );        /* delay */
  596.  
  597.     goxy( x, y );
  598.     putchar( ' ' );
  599. }
  600.  
  601. /* explosion subroutine */
  602.  
  603. explode( x, y ) 
  604. int x, y;
  605. {
  606.     blast( x, y - 1, '|' );
  607.     blast( x - 2, y, '-' );
  608.     blast( x, y + 1, '|' );
  609.     blast( x + 2, y, '-' );
  610.     blast( x - 2, y - 1, '\\' );    /* explode in a ring around it */
  611.     blast( x - 2, y + 1, '/' );
  612.     blast( x + 2, y + 1, '\\' );
  613.     blast( x + 2, y - 1, '/' );
  614.  
  615.     blast( x, y - 2, ':' );        /* outer ring */
  616.     blast( x - 4, y, ':' );
  617.     blast( x, y + 2, ':' );
  618.     blast( x + 4, y, ':' );
  619.  
  620.     blast( x - 4, y - 2, '.' );
  621.     blast( x + 4, y + 2, '.' );
  622.     blast( x - 4, y + 2, '.' );
  623.     blast( x + 4, y - 2, '.' );
  624. }
  625.  
  626. absdif( x, y )
  627. int x, y;
  628. {
  629.     if( x > y ) return x - y;
  630.         else return y - x;
  631. }
  632.  
  633. sign( x )
  634. int x;
  635. {
  636.     if( x > 0 ) return 1;
  637.     if( x < 0 ) return -1;
  638.     return 0;
  639. }
  640.  
  641. #include "stdlib.c"
  642.  
  643.  
  644.